<template>
  <el-card shadow="never" class="aui-card--fill">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.orderId"
            placeholder="订单编号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <SelectComponent
            dictType="ship_order_state"
            v-model="dataForm.itemState"
            placeholder="订单状态"
          >
          </SelectComponent>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.lineNum"
            placeholder="航线号"
            clearable
          ></el-input>
        </el-form-item>
        <!-- <el-form-item>
                <el-input
                    v-model="dataForm.lineNo"
                    placeholder="航次"
                    clearable
                ></el-input>
            </el-form-item> -->
        <el-form-item>
          <el-input
            v-model="dataForm.lineNo"
            placeholder="航次"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.shipName"
            placeholder="船名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.passName"
            placeholder="乘客姓名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.contactNum"
            placeholder="手机号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.credentialNum"
            placeholder="身份证号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            value-format="yyyy-MM-dd"
            v-model="enterDateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            clearable
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            value-format="yyyy-MM-dd"
            v-model="dataForm.createTime"
            type="date"
            placeholder="下单时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-time-picker
            v-model="dataForm.sailTime"
            value-format="HH:mm"
            placeholder="开船时间"
          >
          </el-time-picker>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            value-format="yyyy-MM-dd"
            v-model="dataForm.sailDate"
            type="date"
            placeholder="开船日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item
          v-if="$hasPermission('travel:isshiporder:refundOrderAndCharge')"
        >
          <el-button type="primary" @click="refundMoreTicket">退票</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="exportHandle()">导出</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%"
        :height="he"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="id"
          label="详情单号"
          header-align="center"
          align="center"
          width="120"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="orderId"
          label="订单编号"
          header-align="center"
          align="center"
          width="170"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="passName"
          label="乘客姓名"
          header-align="center"
          align="center"
          width="100"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <!-- <el-table-column
          prop="credentialNum"
          label="证件号码"
          header-align="center"
          align="center"
          width="170"
          :show-overflow-tooltip="true"
        >
        </el-table-column> -->
        <el-table-column
          label="证件号码"
          header-align="center"
          min-width="170"
          align="center"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <i @click="showReal = scope.$index">{{
              scope.$index === showReal
                ? scope.row.realCredentialNum
                : scope.row.credentialNum
            }}</i>
          </template>
        </el-table-column>
        <!-- <el-table-column
            prop="contactNum"
            label="手机号"
            header-align="center"
            align="center"
            width="120"
            :show-overflow-tooltip="true"
          >
          </el-table-column> -->
        <el-table-column
          label="手机号"
          header-align="center"
          min-width="120"
          align="center"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <i @click="showReal = scope.$index">{{
              scope.$index === showReal
                ? scope.row.realPhone
                : scope.row.contactNum
            }}</i>
          </template>
        </el-table-column>
        <el-table-column
          prop="startPortName"
          label="起始港名"
          header-align="center"
          align="center"
          width="120"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="endPortName"
          label="停靠港名"
          header-align="center"
          align="center"
          width="120"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="realFee"
          label="票价金额"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="lineNum"
          label="航线号"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="lineName"
          label="航线名称"
          header-align="center"
          align="center"
          width="100"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="lineNo"
          label="航次"
          header-align="center"
          align="center"
          width="80"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            {{ scope.row.lineNum }}{{ scope.row.sx }}
          </template>
        </el-table-column>
        <el-table-column
          prop="shipName"
          label="船名"
          header-align="center"
          align="center"
          width="100"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="seatClassName"
          label="舱位等级名称"
          header-align="center"
          align="center"
          width="110"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="sailDate"
          label="开船日期"
          header-align="center"
          align="center"
          width="100"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">{{
            scope.row.sailDate ? scope.row.sailDate.split(" ")[0] : ""
          }}</template>
        </el-table-column>
        <el-table-column
          prop="sailTime"
          label="开船时间"
          header-align="center"
          align="center"
          width="100"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="itemStateName"
          label="订单状态"
          header-align="center"
          align="center"
          width="110"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="订单创建时间"
          header-align="center"
          align="center"
          width="170"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="alterTime"
          label="改签时间"
          header-align="center"
          align="center"
          width="170"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="200"
        >
          <template slot-scope="scope">
            <el-button
              v-if="$hasPermission('travel:isshiporder:refundOrderAndCharge')"
              type="text"
              size="small"
              slot="reference"
              @click="refundTicket(scope.row.id)"
              >退票</el-button
            >
            <el-button
              v-if="$hasPermission('travel:isshiporder:specialRefund')"
              type="text"
              size="small"
              slot="reference"
              @click="refundApply(scope.row.id)"
              >特殊退票申请</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <el-dialog title="温馨提示" :visible.sync="applyShow" width="30%">
        <span>是否确定进行特殊退票申请？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="applyShow = false">取 消</el-button>
          <el-button type="primary" @click="sureRefundApply">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog title="温馨提示" :visible.sync="refundShow" width="30%">
        <span>是否确定进行退票？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="refundShow = false">取 消</el-button>
          <el-button type="primary" @click="sureRefundTicket">确 定</el-button>
        </span>
      </el-dialog>
  </el-card>
</template>
  
  <script>
import mixinViewModule from "@/mixins/view-module";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      he: "auto",
      disabled: false,
      enterDateRange: [],
      mixinViewModuleOptions: {
        getDataListURL: "/travel/isshiporder/pageDetailAndOrder",
        getDataListIsPage: true,
        exportURL: "/travel/isshiporder/pageDetailAndOrderExpert",
      },
      dataForm: {
        sailTime: "",
      },
      applyShow: false,
      refundShow: false,
      id: "",
      ids: [],
      showReal: "",
    };
  },
  created() {
    // let hours = new Date().getHours();
    // let minutes = new Date().getMinutes();
    // this.dataForm.sailTime = (hours<10?('0'+hours):hours)+':'+(minutes<10?('0'+minutes):minutes)+':00';

    this.$http
      .get("/travel/isshiporder/pageDetailAndOrder", {
        params: {
          page: 1,
          limit: 10,
        },
      })
      .then(({ data: res }) => {});
  },
  watch: {
    dataList(newval, oldval) {
      if (newval != oldval) {
        this.he = "auto";
        setTimeout(() => {
          this.he = "calc(100vh - 330px)";
        }, 500);
      }
    },
    "dataForm.itemState": {
      immediate: true,
      deep: true,
      handler(newValue) {},
    },
    enterDateRange: {
      immediate: true,
      deep: true,
      handler(newVal) {
        this.splitTimeRange();
      },
    },
  },
  methods: {
    refundApply(id) {
      this.id = id;
      this.applyShow = true;
    },
    sureRefundApply() {
      this.$http
        .get("/travel/isshiporder/specialRefund/" + this.id)
        .then(({ data: res }) => {
          this.applyShow = false;
          if (res.code === 0) {
            this.$message({
              message: this.$t("prompt.success"),
              type: "success",
              duration: 500,
              onClose: () => {
                this.$emit("refreshDataList");
              },
            });
          } else this.$message.error(res.msg);
        });
    },
    refundTicket(id) {
      this.id = id;
      this.refundShow = true;
    },
    sureRefundTicket() {
      this.toSureRefundTicket([this.id]);
    },
    toSureRefundTicket(ids) {
      this.$http
        .post("/travel/isshiporder/refundOrderAndCharge", ids)
        .then(({ data: res }) => {
          this.refundShow = false;
          if (res.code === 0) {
            this.$message({
              message: this.$t("prompt.success"),
              type: "success",
              duration: 500,
              onClose: () => {
                this.$emit("refreshDataList");
              },
            });
          } else this.$message.error(res.msg);
        });
    },
    dataListSelectionChangeHandle(e) {
      this.ids = e.map((d) => d.id);
    },
    refundMoreTicket() {
      if (this.ids.length == 0)
        return this.$message.error("请至少选择一条数据进行退票");
      this.toSureRefundTicket(this.ids);
    },
    splitTimeRange() {
      if (this.enterDateRange) {
        // 取值
        this.dataForm.sailDateStart = this.enterDateRange[0];
        this.dataForm.sailDateEnd = this.enterDateRange[1];
      } else {
        this.dataForm.sailDateStart = "";
        this.dataForm.sailDateEnd = "";
      }
    },
  },
};
</script>
  